-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace update functions with a merge function #51
Replace update functions with a merge function #51
Conversation
cdb726f
to
99e6914
Compare
Replace the per-channel-per-event update function mapping with a single merge function. This makes the UpdatesRegistry redundant, as we don't need a class to hold the old mapping: "channel -> eventName -> function" Update the tests, and rename some update terminology to merge. Also: - accept the channel name as a constructor argument to the Model. squash
The StreamFactory is now only responsible for creating streams given the channel name and the set of default options. It doesn't hold on to the references to stream after creating them.
99e6914
to
2f9adbd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice LGTM, just some very minor comments
[event: string]: UpdateFunc<T>; | ||
}; | ||
}; | ||
$merge?: MergeFunc<T>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can drop the $ prefixes, wdythink? Originally this was inteneded to distinguish between user-defined functions and those exposed on the model, although we're namespacing so we don't really need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't have to be in this PR - I have created a ticket to do this separately for all registrations: https://ably.atlassian.net/browse/COL-518
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good idea 👍
src/Model.discontinuity.test.ts
Outdated
@@ -9,7 +9,7 @@ import { MutationMethods } from './types/mutations.js'; | |||
|
|||
vi.mock('ably/promises'); | |||
|
|||
interface ModelTestContext extends ModelOptions {} | |||
type ModelTestContext = { channelName: string } & ModelOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just store the channelName
on the ModelOptions
directly?
src/Model.ts
Outdated
logger: options.logger, | ||
eventBufferOptions: options.eventBufferOptions, | ||
}); | ||
this.stream = this.streamFactory.newStream({ channel: channel }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can just be { channel }
Replace the per-channel-per-event update function mapping with a single merge function. This makes the UpdatesRegistry redundant, as we don't need a class to hold the old mapping: "channel -> eventName -> function"
Update the tests, and rename some update terminology to merge.
Also:
channel name and the set of default options. It doesn't hold on to the
references to stream after creating them.